<template>
  <div :class="className"
       :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils';

const animationDuration = 6000

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
          subtext:"党员总数   1397人",
          subtextStyle:{
            color:"white",
            fontSize: 16
          }
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c}'
        },
        series: {
          name: '党员总数',
          type: 'sunburst',
          data: [
            {
              name: '汶上县',
              children: [
                {
                  name: '汶上街道',

                  children: [
                    {
                      name: '西门社区',
                      value: 5
                    },
                    {
                      name: '东门社区',
                      value: 5
                    },
                    {
                      name: '北门社区',
                      value: 5
                    },
                    {
                      name: '东关社区',
                      value: 5
                    },
                    {
                      name: '后周村',
                      value: 5
                    },
                    {
                      name: '中周村',
                      value: 5
                    },
                    {
                      name: '前周村',
                      value: 5
                    },
                    {
                      name: '陈闸村',
                      value: 5
                    },
                    {
                      name: '大刘庄村',
                      value: 5
                    },
                    {
                      name: '八里桥村',
                      value: 5
                    },
                    {
                      name: '路桥村',
                      value: 5
                    }
                  ]
                },
                {
                  name: '南站镇',
                  children: [
                    {
                      name: '南站南村',
                      value: 6
                    },
                    {
                      name: '南站北村',
                      value: 6
                    },
                    {
                      name: '野庄村',
                      value: 6
                    },
                    {
                      name: '潘村',
                      value: 6
                    },
                    {
                      name: '程寺村',
                      value: 6
                    },
                    {
                      name: '代庄村',
                      value: 6
                    },
                    {
                      name: '大街村',
                      value: 6
                    },
                    {
                      name: '齐高村',
                      value: 6
                    },
                    {
                      name: '董王庄',
                      value: 6
                    },
                    {
                      name: '鹅河村',
                      value: 6
                    },
                    {
                      name: '南李街村',
                      value: 6
                    },
                    {
                      name: '漕流村',
                      value: 6
                    },
                    {
                      name: '何楼村',
                      value: 6
                    },
                    {
                      name: '西王村',
                      value: 6
                    },
                    {
                      name: '成村',
                      value: 6
                    },
                    {
                      name: '伊村',
                      value: 6
                    },
                    {
                      name: '石村',
                      value: 6
                    },
                    {
                      name: '南辛庄',
                      value: 6
                    },
                    {
                      name: '黄店南村',
                      value: 6
                    },
                    {
                      name: '黄店北村',
                      value: 6
                    },
                    {
                      name: '赵庙村',
                      value: 6
                    },
                    {
                      name: '龙集村',
                      value: 6
                    },
                    {
                      name: '宋铺村',
                      value: 6
                    },
                    {
                      name: '王庄',
                      value: 6
                    },
                    {
                      name: '西李尹村',
                      value: 6
                    },
                    {
                      name: '后李尹村',
                      value: 6
                    },
                    {
                      name: '东李尹村',
                      value: 6
                    },
                    {
                      name: '东尚庄',
                      value: 6
                    },
                    {
                      name: '高胡同村',
                      value: 6
                    },
                    {
                      name: '徐大庄',
                      value: 6
                    },
                    {
                      name: '西尚庄',
                      value: 6
                    },
                    {
                      name: '辛店村',
                      value: 6
                    },
                    {
                      name: '李岗村',
                      value: 6
                    },
                    {
                      name: '廉街村',
                      value: 6
                    },
                    {
                      name: '李街村',
                      value: 6
                    },
                    {
                      name: '岗子村',
                      value: 6
                    },
                    {
                      name: '桥口村',
                      value: 6
                    },
                    {
                      name: '曹堂村',
                      value: 6
                    },
                    {
                      name: '三官庙村',
                      value: 6
                    },
                    {
                      name: '路林村',
                      value: 6
                    },
                    {
                      name: '孟庄',
                      value: 6
                    },
                    {
                      name: '鹿庄',
                      value: 6
                    },
                    {
                      name: '前集村',
                      value: 6
                    },
                    {
                      name: '张杭村',
                      value: 6
                    },
                    {
                      name: '骆庄',
                      value: 6
                    },
                    {
                      name: '关帝庙村',
                      value: 6
                    },
                    {
                      name: '东田庄',
                      value: 6
                    },
                    {
                      name: '梁桥村',
                      value: 6
                    },
                    {
                      name: '樊村',
                      value: 6
                    },
                    {
                      name: '姬村',
                      value: 6
                    },
                    {
                      name: '东孙庄',
                      value: 6
                    },
                    {
                      name: '李海村',
                      value: 6
                    },
                    {
                      name: '刘许铺村',
                      value: 6
                    },
                    {
                      name: '刘黑村',
                      value: 6
                    }
                  ]
                },
                {
                  name: '唐驿镇',
                  value: 40
                },
                {
                  name: '南旺镇',
                  value: 46
                },
                {
                  name: '刘楼镇',
                  value: 49
                },
                {
                  name: '次邱镇',
                  value: 30
                },
                {
                  name: '寅寺镇',
                  value: 70
                },
                {
                  name: '郭楼镇',
                  value: 90
                },
                {
                  name: '郭仓镇',
                  value: 99
                },
                {
                  name: '杨店镇',
                  value: 99
                },
                {
                  name: '军屯乡',
                  value: 99
                },
                {
                  name: '白石镇',
                  value: 99
                },
                {
                  name: '苑庄镇',
                  value: 99
                },
                {
                  name: '义桥镇',
                  value: 99
                },
                {
                  name: '中都街道',
                  value: 99
                }
              ]
            }
          ],
          radius: [0, '90%'],
          label: {
            rotate: 'radial'
          }
        }
      })
    }
  }
}
</script>
